package appapi.controller.oider;

import appapi.Global.BusinessException;
import appapi.Request.*;
import appapi.Request.Basic.DelEquipImportReq;
import appapi.Request.Basic.GetEquipImportReq;
import appapi.Request.record.BindEquipmentReq;
import appapi.Vo.AppVo.ExcelEquipVo;
import appapi.Vo.AppVo.ExecelEquipVos;
import appapi.Vo.GetDismantPageVo;
import appapi.Vo.GetEquipOperPageVo;
import appapi.Vo.UpdateImportEquipVo;
import appapi.common.BusinessTypeEnum;
import appapi.common.ResponseBean;
import appapi.config.MyLog;
import appapi.dao.EquipmentMapper;
import appapi.dto.*;
import appapi.config.CurrentUser;
import appapi.dto.basic.EquipNoDto;
import appapi.dto.basic.GenerateImportDto;
import appapi.entity.Zhongjiao.EquipmentDto;
import appapi.entity.Zhongjiao.EquipmentdismantDto;
import appapi.entity.basic.UserInfo;
import appapi.model.ResponseDataModel;
import appapi.model.ResponseModel;
import appapi.service.*;
import appapi.utils.ExcelUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author djq
 * @date 2023/5/16 15:12
 * @description:
 */

@Api(tags = "设备管理-进场验收")
@RestController
@RequestMapping(value = "/api/device")
public class DeviceController {
    @Resource
    private IEquipmentService iEquipmentService;
    @Resource
    private IEquipoperatorService iEquipoperatorService;
    @Resource
    private IEquipmentdismantService iEquipmentdismantService;
    @Resource
    private IAnnexService iAnnexService;
    @Resource
    private IAppApiService iAppApiService;

    @Resource
    IStaffService istaffService;

    //region 设备信息

    /**
     * 设备信息的分页查询
     *
     * @return
     * @author djq 2023/5/17
     */
    @ApiOperation(value = "设备信息的分页查询", notes = "设备信息的分页查询")
    @GetMapping(value = "/GetEquipmentListByPage")
    public ResponseBean GetEquipmentListByPage(@CurrentUser UserInfo userInfo,@Valid EquiPageReq equiPageReq) {
        try {
            if (equiPageReq.getCurrPage() == null || equiPageReq.getPageSize() == null) {
                equiPageReq.setCurrPage(1);
                equiPageReq.setPageSize(10);
            }
            List<Map<String, Object>> projects = iEquipmentService.SelectEquipmentPage(userInfo.getUserid(),equiPageReq);
            PageInfo pageInfo = new PageInfo(projects, equiPageReq.getPageSize());

            return ResponseBean.success(pageInfo);
        } catch (BusinessException exception) {
            return ResponseBean.fail("设备信息的分页异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 进场验收导出
     *
     * @return
     * @author lc 2023/06/12
     */
    @ApiOperation(value = "进场验收导出", notes = "进场验收导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/EquipmentsRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "进场验收导出",businessType = BusinessTypeEnum.export)
    public ResponseBean EquipmentRecExport(EquiPageReq req, HttpServletResponse response) {
        try {
            List<ExcelEquipVo> list = iEquipmentService.getList(req);
            if (list.size() == 0) {
                return ResponseBean.success("数据源为空");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "进场验收", "进场验收sheet", ExcelEquipVo.class, "进场验收", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("进场验收导出异常");
        }
    }

    /**
     * 总台账导出
     *
     * @return
     * @author lc 2023/06/12
     */
    @ApiOperation(value = "总台账导出", notes = "总台账导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/EquipmentsRecExports")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "总台账导出",businessType = BusinessTypeEnum.export)
    public ResponseBean EquipmentRecExports(@CurrentUser UserInfo userInfo,EquiPageReq req, HttpServletResponse response) {
        try {
            List<ExecelEquipVos> list = iEquipmentService.getLists(userInfo,req);
//            List<ExecelEquipVos> list = iEquipmentService.SelectEquipmentPages(userInfo,req);
            if (list.size() == 0) {
                return ResponseBean.success("数据源为空");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "总台账", "总台账sheet", ExecelEquipVos.class, "总台账", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("总台账导出异常");
        }
    }


    @GetMapping(value = "exportEquipTemp", produces = "application/octet-stream")
    @ApiOperation(value = "获取设备导入模版")
    @MyLog(title = "获取设备导入模版",businessType = BusinessTypeEnum.eximport)
    public void exportExample(HttpServletResponse response) throws IOException {
        List<ExcelEquipVo> dataList = new ArrayList<>();
        ExcelEquipVo vo = new ExcelEquipVo();
        vo.setEquipName("测试设备");
        vo.setEquipTypeName("塔式起重机");
        vo.setEquipNo("msqzj-zy-0001");
        vo.setEquipSource(0);
        vo.setMonitoringCode("sqf-xd-0001");
        vo.setEquidTerminal("ds");
        vo.setWechatCode("http://47.104.195.180:8080/images/recwxCodeImage/87ac140e-d686-4416-bdc9-a832028b28fe--3.jpg");
        vo.setProjName("中电科项目");
        vo.setEquipStatus(0);
        vo.setActQuitDate(new Date());
        dataList.add(vo);
        ExcelUtils.exportExcel(dataList, "进场验收模版", "进场验收sheet", ExcelEquipVo.class, "进场验收模版", true, response);
    }


    @ApiOperation(value = "进场验收导入")
    @PostMapping("/importEquipments")
    @MyLog(title = "进场验收导入",businessType = BusinessTypeEnum.eximport)
    public ResponseBean EquipmentRecImport(@RequestParam("file") MultipartFile file) {
        try {
            List<ExcelEquipVo> list = ExcelUtils.importExcel(file, 1, 1, true, ExcelEquipVo.class);
            if (list == null) {
                return ResponseBean.fail("数据为空");
            }
            if (list.size() == 0) {
                return ResponseBean.fail("数据为空");
            }
            GenerateImportDto model = iEquipmentService.EquipmentRecImport(list);
            if (model != null) {
                return ResponseBean.success(model);
            } else {
                return ResponseBean.fail();
            }
        } catch (Exception e) {
            //logger.error("导入设备类型出错", e);
            return ResponseBean.fail("导入设备类型出错");
        }
    }

    @ApiOperation(value = "进场验收导入查询", notes = "进场验收导入的分页查询")
    @GetMapping(value = "/GetEquipmentListByImport")
    public ResponseBean GetEquipmentListByImport(GetEquipImportReq req) {
        try {
            Map pageInfo = iEquipmentService.getWaitEquipmentListByPage(req);
            return ResponseBean.success(pageInfo);
        } catch (Exception e) {
            return ResponseBean.fail("分页查询待保存记录出错");
        }
    }
    @ApiOperation(value = "进场验收导入--编辑")
    @PostMapping("/updateImportEquip")
    @MyLog(title = "编辑进场验收导入",businessType = BusinessTypeEnum.update)
    public ResponseBean updateImportEquip(@RequestBody UpdateImportEquipVo updateImportEquipVo){
        try {
            GenerateImportDto dto=iEquipmentService.updateImportEquip(updateImportEquipVo);
            return ResponseBean.updateSuccess(dto);
        } catch (Exception e) {
            return ResponseBean.fail("修改导入设备异常");
        }
    }
    @ApiOperation(value = "进场验收导入--删除", notes = "进场验收导入--删除")
    @PostMapping (value = "/deleteEquipmentsList")
    @ResponseBody
    @MyLog(title = "删除进场验收导入",businessType = BusinessTypeEnum.delete)
    public ResponseBean  deleteEquipTypeList(@RequestBody DelEquipImportReq req) {
        try {
            GenerateImportDto dto=   iEquipmentService.deliEquipmentRedis(req);
            return ResponseBean.deleteSuccess(dto);
        } catch (Exception ex) {
            return ResponseBean.fail("删除失败");
        }
    }

    /**
     * 保存进场验收导入
     * @param
     * @return
     */
    @ApiOperation(value = "保存进场验收导入")
    @PostMapping("/saveImportEquipments")
    @MyLog(title = "保存进场验收导入",businessType = BusinessTypeEnum.insert)
    public ResponseBean saveImportEquipments(@RequestBody SaveImportReq req){
        try {
            List<Object> list = iEquipmentService.getEquipTypeListFromRedis(req);
            for (Object model : list) {
                String json = JSON.toJSONString(model);
                EquipmentDto record = JSON.parseObject(json, new TypeReference<EquipmentDto>() {
                });
                iEquipmentService.insertExcelEquip(record);
            }
            return ResponseBean.success();
        } catch (Exception e) {
            return ResponseBean.fail("保存导入设备异常");
        }
    }


    /**
     * 获取设备详情
     *
     * @return
     * @author djq 2023/5/17
     */
    @ApiOperation(value = "获取设备详情", notes = "获取设备详情")
    @GetMapping(value = "/GetProjectById")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "equipId", dataType = "Long", required = true, value = "设备Id")
    })
    public ResponseBean GetEquipmentById(@Valid Long equipId) {
        try {
            Map<String, Object> map = iEquipmentService.SelectEquipmentDetail(equipId);

            return ResponseBean.success(map);
        } catch (BusinessException exception) {
            return ResponseBean.fail("查询管理人员详情异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 添加设备信息
     *
     * @return
     * @author djq 2023/5/17
     */
    @ApiOperation(value = "进场验收-添加设备信息", notes = "添加设备信息")
    @PostMapping(value = "/AddEquipment")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "formData", name = "equipmentDto", dataType = "object", value = "设备参数")
    })
    @MyLog(title = "进场验收-添加设备信息",businessType = BusinessTypeEnum.insert)
    public ResponseBean AddEquipment(@CurrentUser UserInfo userInfo,@Validated @RequestBody EquipmentDto equipmentDto) {
        try {

            equipmentDto.setCreateUser(userInfo.getUsername());
            iEquipmentService.InsertEquipment(equipmentDto);
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("添加设备异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 编辑设备信息
     *
     * @return
     * @author djq 2023/5/17
     */
    @ApiOperation(value = "编辑设备信息", notes = "编辑设备信息")
    @PostMapping(value = "/updateEquipment")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "formData", name = "equipmentDto", dataType = "object", value = "设备参数")
    })
    @MyLog(title = "进场验收-编辑设备信息",businessType = BusinessTypeEnum.update)
    public ResponseBean updateEquipment(@CurrentUser UserInfo userInfo,@Validated @RequestBody EquipmentDto equipmentDto) {
        try {

            equipmentDto.setCreateUser(userInfo.getUsername());
            iEquipmentService.UpdateEquipment(equipmentDto);

            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("编辑设备信息异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 设备绑定终端
     *
     * @return
     * @author djq 2023/5/17
     */
    @ApiOperation(value = "设备绑定终端", notes = "设备绑定终端")
    @PostMapping(value = "/equipmentBind")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "formData", name = "dto", dataType = "object", value = "设备参数")
    })
    @MyLog(title = "进场验收-设备绑定终端",businessType = BusinessTypeEnum.update)
    public ResponseBean equipmentBinding(@Validated @RequestBody BindEquipmentReq dto) {
        try {

           if(iEquipmentService.equipmentBind(dto)==0){
               return ResponseBean.fail("设备绑定失败");
           }
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("设备绑定终端异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 删除设备信息
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "删除设备", notes = "删除设备")
    @PostMapping(value = "/delEquipment")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "equipId", dataType = "Long", required = true, value = "设备id")
    })
    @MyLog(title = "删除设备",businessType = BusinessTypeEnum.delete)
    public ResponseBean delEquipment(@Valid @RequestBody DelEquipDto dto) {
        try {
            if (iEquipmentService.DelEquipment(dto.getEquipId()) == 0) {
                return ResponseBean.fail("删除失败");
            }
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("删除设备: ".concat(exception.getMessage()));
        }
    }

    //endregion

    //region 设备类型

    /**
     * 设备类型查询
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "设备类型查询", notes = "设备类型查询")
    @GetMapping(value = "/GetEquipmentTypeList")
    public ResponseBean GetEquipmentTypeList() {
        try {
            List<Map<String, Object>> list = iAppApiService.GetEquipmenttype();
            return ResponseBean.success(list);
        } catch (BusinessException exception) {
            return ResponseBean.fail("设备类型查询异常");
        }
    }
    //endregion

    //region 设备-人员

    /**
     * 查询设备人员列表
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "查询设备人员列表", notes = "查询设备人员列表")
    @GetMapping(value = "/GetEquipmentOperList")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "equipId", dataType = "Long", required = true, value = "设备id")
    })
    public ResponseBean GetEquipmentOperList(@Valid Long equipId) {
        try {

            List<Map<String, Object>> list = iEquipoperatorService.SelectList(equipId);

            return ResponseBean.success(list);
        } catch (BusinessException exception) {
            return ResponseBean.fail("查询设备人员列表异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 查询设备人员分页
     *
     * @return
     * @auther djq 2023/6/12
     */
    @ApiOperation(value = "查询设备人员分页", notes = "查询设备人员分页")
    @GetMapping(value = "/GetEquipmentOperPage")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "equipId", dataType = "Long", required = true, value = "设备id")
    })
    public ResponseBean<GetEquipOperPageVo> GetEquipmentOperPage(@CurrentUser UserInfo userInfo, EquipOperPageReq req) {
        try {
            if (req.getCurrPage() == null || req.getPageSize() == null) {
                req.setCurrPage(1);
                req.setPageSize(10);
            }
            List<GetEquipOperPageVo> list = iEquipoperatorService.SelectPage(userInfo, req);

            PageInfo pageInfo = new PageInfo(list, req.getPageSize());

            return ResponseBean.success(pageInfo);
        } catch (BusinessException exception) {
            return ResponseBean.fail("查询设备人员分页异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 设备人员导出
     *
     * @return
     * @auther ygp 2023/6/12
     */
    @ApiOperation(value = "设备操作员导出", notes = "设备操作员导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/EquipmentRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "设备操作员导出",businessType = BusinessTypeEnum.export)
    public ResponseBean EquipmentRecExport(EquipOperPageReq req, HttpServletResponse response) {
        try {
            List<GetEquipOperPageVo> list = iEquipoperatorService.getList(req);
            if (list.size() == 0) {
                return ResponseBean.fail("未查询到数据");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "设备操作员信息", "设备操作员信息sheet", GetEquipOperPageVo.class, "设备操作员信息", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("设备信息导出异常");
        }
    }

    /**
     * 设备人员添加
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "设备人员添加", notes = "设备人员添加")
    @PostMapping(value = "/AddEquipmentOper")
    @MyLog(title = "设备人员添加",businessType = BusinessTypeEnum.insert)
    public ResponseBean AddEquipmentOper(@Valid @RequestBody EquipmentOperListReq req) {
        try {
            iEquipoperatorService.InsertEquipmentOper(req);
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("设备人员添加异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 设备人员删除
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "设备人员删除", notes = "设备人员删除")
    @PostMapping(value = "/DeleteEquipmentOper")
    @MyLog(title = "设备人员删除",businessType = BusinessTypeEnum.delete)
    public ResponseBean DeleteEquipmentOper(@Valid @RequestBody DelEquipOperDto dto) {
        try {

            iEquipoperatorService.DelEquipmentOper(dto);
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("设备人员删除异常: ".concat(exception.getMessage()));
        }
    }

    //endregion

    //region 设备安拆

    /**
     * 设备安拆信息分页表查询
     *
     * @return
     * @auther djq 2023/6/1
     */
    @ApiOperation(value = "设备安拆信息分页表查询", notes = "设备安拆信息分页表查询")
    @GetMapping(value = "/GetDismantPage")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "req", dataType = "Long", required = true, value = "设备id")
    })
    public ResponseBean<GetDismantPageVo> GetDismantPage(@CurrentUser UserInfo userInfo, DismantReq req) {
        try {
            if (req.getCurrPage() == null || req.getPageSize() == null) {
                req.setCurrPage(1);
                req.setPageSize(10);
            }

            List<GetDismantPageVo> list = iEquipmentdismantService.SelectDismantPage(userInfo, req);

            PageInfo pageInfo = new PageInfo(list, req.getPageSize());

            return ResponseBean.success(pageInfo);
        } catch (BusinessException exception) {
            return ResponseBean.fail("设备安拆信息分页表查询异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 安拆信息导出
     *
     * @return
     * @author lc 2023/06/12
     */
    @ApiOperation(value = "安拆信息导出", notes = "安拆信息导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/RectificationRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "安拆信息导出",businessType = BusinessTypeEnum.export)
    public ResponseBean RectificationRecExport(DismantReq req, HttpServletResponse response) {
        try {
            List<GetDismantPageVo> list = iEquipmentdismantService.getList(req);
            if (list.size() == 0) {
                return ResponseBean.fail("未查询到数据");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "安拆信息", "安拆信息sheet", GetDismantPageVo.class, "安拆信息", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("安拆信息导出异常");
        }
    }

    /**
     * 设备安拆信息列表查询
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "设备安拆信息列表查询", notes = "设备安拆信息列表查询")
    @GetMapping(value = "/GetDismantList")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "equipId", dataType = "Long", required = true, value = "设备id")
    })
    public ResponseModel GetDismantList(Long equipId) {
        ResponseDataModel responseModel = new ResponseDataModel();
        try {

            List<Map<String, Object>> list = iEquipmentdismantService.SelectDismantList(equipId);

            responseModel.setData(list);
            responseModel.setRcount(list.size());
        } catch (BusinessException exception) {

            responseModel.setMessage("设备安拆信息列表查询异常: ".concat(exception.getMessage()));
            responseModel.setCode(exception.getCode());
        }
        return responseModel;
    }

    /**
     * 获取安拆详情
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "获取安拆详情", notes = "获取安拆详情")
    @GetMapping(value = "/GetDismantById")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "dismId", dataType = "Long", required = true, value = "Id")
    })
    public ResponseModel GetDismantById(@Valid Long dismId) {
        ResponseDataModel responseModel = new ResponseDataModel();
        try {
            Map<String, Object> map = iEquipmentdismantService.SelectDismantDetail(dismId);
            responseModel.setData(map);
        } catch (BusinessException exception) {
            responseModel.setMessage("获取安拆详情异常: ".concat(exception.getMessage()));
            responseModel.setCode(exception.getCode());
        }
        return responseModel;
    }

    /**
     * 添加安拆信息
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "添加安拆信息", notes = "添加安拆信息")
    @PostMapping(value = "/AddDismant")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "formData", name = "dto", dataType = "object", value = "安拆信息参数")
    })
    @MyLog(title = "添加安拆信息",businessType = BusinessTypeEnum.insert)
    public ResponseBean AddDismant(@CurrentUser UserInfo userInfo ,@Validated @RequestBody EquipmentdismantDto dto) {
        try {
            dto.setCreateUser(userInfo.getUsername());
            iEquipmentdismantService.InsertEquipmentdismant(dto);
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("添加安拆信息异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 编辑安拆信息
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "编辑安拆信息", notes = "编辑安拆信息")
    @PostMapping(value = "/EditDismant")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "formData", name = "dto", dataType = "object", value = "安拆参数")
    })
    @MyLog(title = "编辑安拆信息",businessType = BusinessTypeEnum.update)
    public ResponseBean EditDismant(@CurrentUser UserInfo userInfo ,@Validated @RequestBody EquipmentdismantDto dto) {
        try {
            dto.setCreateUser(userInfo.getUsername());
            iEquipmentdismantService.UpdateEquipmentdismant(dto);
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("编辑安拆信息异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 删除安拆信息
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "删除安拆信息", notes = "删除安拆信息")
    @PostMapping(value = "/DeleteDismant")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "dismId", dataType = "Long", required = true, value = "安拆id")
    })
    @MyLog(title = "删除安拆信息",businessType = BusinessTypeEnum.delete)
    public ResponseBean DeleteDismant(@Valid @RequestBody DelDismDto dto) {
        try {
            if (iEquipmentdismantService.DelEquipmentdismant(dto.getDismId()) == 0) {
                return ResponseBean.fail("删除失败");
            }
            return ResponseBean.success();
        } catch (BusinessException exception) {
            return ResponseBean.fail("删除安拆信息异常: ".concat(exception.getMessage()));
        }
    }

    //endregion

    //region 附件

    /**
     * 查询附件列表(未完成)
     *
     * @return
     * @auther djq 2023/5/17
     */
    @ApiOperation(value = "查询附件列表", notes = "查询附件列表")
    @GetMapping(value = "/GetAnnexList")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "selfId", dataType = "Long", required = true, value = "人员Id"),
            @ApiImplicitParam(paramType = "query", name = "annexType", dataType = "Long", required = true, value = "附件类型")
    })
    public ResponseModel GetAnnexList(@Valid Long selfId, String annexType) {
        ResponseDataModel responseModel = new ResponseDataModel();
        try {

            List<Map<String, Object>> list = iAnnexService.SelectAnnexList(selfId, annexType);

            responseModel.setData(list);
            responseModel.setRcount(list.size());
        } catch (BusinessException exception) {

            responseModel.setMessage("设备安拆信息列表查询异常: ".concat(exception.getMessage()));
            responseModel.setCode(exception.getCode());
        }
        return responseModel;
    }

    /**
     * 自有设备台账记录导出
     * @param equiPageReq
     * @param response
     * @return
     */
    @ApiOperation(value = "自有设备台账记录导出", notes = "自有设备台账记录导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/OwnEquipRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "自有设备台账记录导出",businessType = BusinessTypeEnum.export)
    public ResponseBean OwnEquipRecExport(@CurrentUser UserInfo userInfo,EquiPageReq equiPageReq,HttpServletResponse response){
        try {
            //如果什么都没传,则查到该账号的所属机构显示数据
            if (equiPageReq.getOrgaPathIds() == null) {
                //拿到人员信息
                Map<String, Object> staffDto = istaffService.SelectStaffDetail(userInfo.getUserid());
                String orgaPathIds = staffDto.get("orgaPathIds").toString();
                equiPageReq.setOrgaPathIds(orgaPathIds);
            }
            List<EquiPageReqModel> list = iEquipmentService.getEquipList(equiPageReq);
            if (list.size() == 0) {
                return ResponseBean.fail("未查询到数据");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "自有设备台账记录", "自有设备台账记录sheet", EquiPageReqModel.class, "自有设备台账记录", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("自有设备台账记录导出异常");
        }

    }

    /**
     * 外租设备台账记录导出
     * @param equiPageReq
     * @param response
     * @return
     */
    @ApiOperation(value = "外租设备台账记录导出", notes = "外租设备台账记录导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/LeasedEquipRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "外租设备台账记录导出",businessType = BusinessTypeEnum.export)
    public ResponseBean LeasedEquipRecExport(@CurrentUser UserInfo userInfo,EquiPageReq equiPageReq,HttpServletResponse response){
        try {
            //如果什么都没传,则查到该账号的所属机构显示数据
            if (equiPageReq.getOrgaPathIds() == null) {
                //拿到人员信息
                Map<String, Object> staffDto = istaffService.SelectStaffDetail(userInfo.getUserid());
                String orgaPathIds = staffDto.get("orgaPathIds").toString();
                equiPageReq.setOrgaPathIds(orgaPathIds);
            }
            List<EquiPageReqModel> list = iEquipmentService.getEquipList(equiPageReq);
            if (list.size() == 0) {
                return ResponseBean.fail("未查询到数据");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "外租设备台账记录", "外租设备台账记录sheet", EquiPageReqModel.class, "外租设备台账记录", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("外租设备台账记录导出异常");
        }

    }

    /**
     * 特种设备台账记录导出
     * @param equiPageReq
     * @param response
     * @return
     */
    @ApiOperation(value = "特种设备台账记录导出", notes = "特种设备台账记录导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/SpecialEquipRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "特种设备台账记录导出",businessType = BusinessTypeEnum.export)
    public ResponseBean SpecialEquipRecExport(@CurrentUser UserInfo userInfo,EquiPageReq equiPageReq,HttpServletResponse response){
        try {
            //如果什么都没传,则查到该账号的所属机构显示数据
            if (equiPageReq.getOrgaPathIds() == null) {
                //拿到人员信息
                Map<String, Object> staffDto = istaffService.SelectStaffDetail(userInfo.getUserid());
                String orgaPathIds = staffDto.get("orgaPathIds").toString();
                equiPageReq.setOrgaPathIds(orgaPathIds);
            }
            List<EquiPageReqModel> list = iEquipmentService.getEquipList(equiPageReq);
            if (list.size() == 0) {
                return ResponseBean.fail("未查询到数据");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "特种设备台账记录", "特种设备台账记录sheet", EquiPageReqModel.class, "特种设备台账记录", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("特种设备台账记录导出异常");
        }

    }

    /**
     * 队伍自带设备台账记录导出
     * @param equiPageReq
     * @param response
     * @return
     */
    @ApiOperation(value = "队伍自带设备台账记录导出", notes = "队伍自带设备台账记录导出接口", produces = "application/octet-stream")
    @GetMapping(value = "/BringEquipRecExport")
    @ApiOperationSupport(ignoreParameters = {"currPage", "pageSize"})
    @MyLog(title = "队伍自带设备台账记录导出",businessType = BusinessTypeEnum.export)
    public ResponseBean BringEquipRecExport(@CurrentUser UserInfo userInfo,EquiPageReq equiPageReq,HttpServletResponse response){
        try {
            //如果什么都没传,则查到该账号的所属机构显示数据
            if (equiPageReq.getOrgaPathIds() == null) {
                //拿到人员信息
                Map<String, Object> staffDto = istaffService.SelectStaffDetail(userInfo.getUserid());
                String orgaPathIds = staffDto.get("orgaPathIds").toString();
                equiPageReq.setOrgaPathIds(orgaPathIds);
            }
            List<EquiPageReqModel> list = iEquipmentService.getEquipList(equiPageReq);
            if (list.size() == 0) {
                return ResponseBean.fail("未查询到数据");
            } else if (list.size() > 5000) {
                return ResponseBean.fail("记录超过5000，请重新选择查询条件");
            } else {
                ExcelUtils.exportExcel(list, "队伍自带设备台账记录", "队伍自带设备台账记录sheet", EquiPageReqModel.class, "队伍自带设备台账记录", response);
                return ResponseBean.success();
            }
        } catch (Exception e) {
            return ResponseBean.fail("队伍自带设备台账记录导出异常");
        }

    }

    //endregion

    /**
     * 获取设备编号
     *
     * @return
     * @author djq 2023/5/17
     */
    @ApiOperation(value = "获取设备编号", notes = "获取设备编号")
    @GetMapping(value = "/GetEquipNo")
    public ResponseBean GetEquipNo(@Valid EquipNoDto dto) {
        try {
            return ResponseBean.success(iEquipmentService.getEquipNo(dto));
        } catch (BusinessException exception) {
            return ResponseBean.fail("获取设备编号异常: ".concat(exception.getMessage()));
        }
    }

    /**
     * 获取设备微信二维码
     *
     * @return
     * @author djq 2023/6/21
     */
    @ApiOperation(value = "获取设备微信二维码", notes = "获取设备微信二维码")
    @PostMapping(value = "/GetEquipWxCode")
    public ResponseBean GetEquipWxCode(@Valid @RequestBody WxCodeDto dto) {
        try {
            String equipWxCode = iEquipmentService.getEquipWxCode(dto);
            return ResponseBean.success(equipWxCode);
        } catch (BusinessException exception) {
            return ResponseBean.fail("获取设备微信二维码异常: ".concat(exception.getMessage()));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
